﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Hawaii.Services.Client;
using Hawaii.Services.Client.Relay;

namespace PhoneApp1
{
    public partial class NameChange : PhoneApplicationPage
    {
        public NameChange()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Helper method to display messages.
        /// </summary>
        /// <param name="message">A valid message.</param>
        /// <param name="caption">A valid caption.</param>
        private void DisplayMessage(string message, string caption)
        {
            this.Dispatcher.BeginInvoke(
                    delegate
                    {
                        MessageBox.Show(message, caption, MessageBoxButton.OK);
                    });
        }

        private void Login_Click(object sender, RoutedEventArgs e)
        {
            /* make sure the user entered a name */
            if (this.Name_Textbox.Text == "")
            {
                this.DisplayMessage("You must enter a name", "Error");
            }
            else
            {
                /* if a name was entered */
                ((App)App.Current).fileStorage.df.login.Change_Name(this.Name_Textbox.Text);

                /* go back to the main page */
                NavigationService.GoBack();
            }

        }
    }
}
